package com.fgi.springframework.beans.factory.support;

import com.fgi.springframework.beans.factory.config.SingletonBeanRegistry;

import java.util.HashMap;
import java.util.Map;

/**
 * @author HanXu
 * @date 2022/11/24
 **/
public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry {

    /**
     * 实例容器
     */
    private final Map<String, Object> singletonObjects = new HashMap<>();

    /**
     * 获取单例实例
     *
     * @param beanName 单例名称
     * @return 实例
     */
    @Override
    public Object getSingleton(String beanName) {
        return singletonObjects.get(beanName);
    }

    /**
     * 添加单例到容器中
     *
     * @param beanName 实例名称
     * @param singletonObject 实例
     */
    protected void addSingleton(String beanName, Object singletonObject) {
        singletonObjects.put(beanName, singletonObject);
    }

}

